<?
class View_Country{
	
  /**
   * получем города
   * 
   * $arrCountry
   * 
   */
  public static function showCitySelect($idCountry = NULL, $idCity = NULL){
  	if (empty($idCountry) AND empty($idCity)) {//если у пользователя ничего не заполнено
  		$arrCountry = Service_Country::getFirstCountry();
  		// определяем город
  		$idCity = Service_Country::getIdCityFromIP();
  		// страну
  		$idCountry = Service_Country::getIdCountryFromIdCity($idCity);
  		
  		// показываем полный список стран, и только предопределенный город
  		
	  	echo '
				<select name="country" id="country" onChange="showCity(this); return false;">
					<option value="NULL" class="timed">-Выбрите страну-</option>';
	  		foreach ($arrCountry as $arrCountry){
					echo '<option class="timed" value="' . $arrCountry['id_country'] . '">' . $arrCountry['name'] . '</option>';
	  		}
			echo '
				<option class="timed" id="coutryAll" value="allCountry">-Показать полный список-</option>
			</select>
			<select disabled="" class="no_active" name="city" id="city" onChange="showAllCity(this); return false;">
				<option value="NULL" id="timedCity">-Укажите страну-</option>
			</select>';
  	}
  	elseif (empty($idCity)) {//если не указан город
  		$arrCountry = Service_Country::getAllCountry();
  		echo '
  			<select name="country" id="country" onChange="showCity(this); return false;">
					<option value="NULL" >-Выберите страну-</option>';
					foreach ($arrCountry as $arrCountry){
						$idCountry == $arrCountry['id_country'] ? $selected='selected="selectted"' : $selected = NULL;
					echo '<option value="' . $arrCountry['id_country'] . '" ' . $selected . ' >' . $arrCountry['name'] . '</option>';
  		}
  		echo '</select>';

  		$arrCity = User_User::getFirstCity($idCountry);
  		echo '
  		<select name="city" id="city" onChange="showAllCity(this); return false;">
				<option class="timedCitySelect" value="">-Выберите город-</option>';
					foreach ($arrCity as $arrCity){
		  			$idCity == $arrCity['id_city'] ? $selected='selected="selectted"' : $selected = NULL;
	  			echo '<option ' . $selected . ' class="timedCity" value="' . $arrCity['id_city'] . '">' . $arrCity['name'] . '</option>';
  		}
			echo '
				<option class="timedCity" value="showAllCity">-Показать все города-</option>
			</select>';
  	}
  	else{
  		$arrCountry = Service_Country::getAllCountry();
  		echo '
  			<select name="country" id="country" onChange="showCity(this); return false;">
					<option value="NULL">-Выберите страну-</option>';
					foreach ($arrCountry as $arrCountry){
						$idCountry == $arrCountry['id_country'] ? $selected='selected="selectted"' : $selected = NULL;
					echo '<option value="' . $arrCountry['id_country'] . '" ' . $selected . '>' . $arrCountry['name'] . '</option>';
  		}
  		echo '</select>';


  		$arrCity = Service_Country::getFirstCity($idCountry);
  		echo '
			<select name="city" id="city" onChange="showAllCity(this); return false;"">
				<option class="timedCitySelect" value="">-Выберите город-</option>';
					foreach ($arrCity as $arrCity){
		  			$idCity == $arrCity['id_city'] ? $selected='selected="selectted"' : $selected = NULL;
		  			!empty($selected) ? $cityIsset = true : NULL;
	  			echo '<option ' . $selected . ' class="timedCity" value="' . $arrCity['id_city'] . '">' . $arrCity['name'] . '</option>';
  		}
  		if ($cityIsset != true){
  			$cityName = Service_Country::getCityNameById($idCity);
  			echo '<option selected="selectted" class="timedCity" value="' . $idCity . '">' . $cityName . '</option>';
  		}
			echo '
				<option class="timedCity" value="showAllCity">-Показать все города-</option>
			</select>';

  	}
  	
  	?>
  	<script type="text/javascript">
/*		$(document).ready(function () {
			$("#city").autocomplete("city.php", {
			delay:10,
			minChars:1,
			matchSubset:1,
			autoFill:true,
			matchContains:1,
			cacheLength:10,
			selectFirst:true,
			maxItemsToShow:10
			}); 	
		});  */	
  	</script>
  	<?
  }
	
	
  
  
  
  
  public static function showCitySelectTest($idCountry = NULL, $idCity = NULL){
  	
  	
  	if (empty($idCountry) AND empty($idCity)) {//если у пользователя ничего не заполнено

  		// определяем город
  		$idCity = Service_Country::getIdCityFromIP();
  		// страну
  		$idCountry = Service_Country::getIdCountryFromIdCity($idCity);  		
  		
  		// определяем топ стран, включая определенную по geoip страну
  		$arrCountry = Service_Country::getFirstCountry($idCountry);
  		
  		// показываем полный список стран
	  	echo '
				<select name="country" id="country" onChange="showCity(this); return false;">
					<option value="NULL" class="timed">-Выбрите страну-</option>';
	  		foreach ($arrCountry as $arrCountry){
					$idCountry == $arrCountry['id_country'] ? $selected='selected="selected"' : $selected = NULL;
					echo '<option class="timed" value="' . $arrCountry['id_country'] . '" ' . $selected . ' >' . $arrCountry['name'] . '</option>';
	  		}
			echo '
				<option class="timed" id="coutryAll" value="allCountry">-Показать полный список-</option>
			</select>';
			
  		// получаем топ городов страны, включая определенный по ip
  		$arrCity = Service_Country::getFirstCity($idCountry, $idCity);
  		
  		
  		$txt = '
  		<select name="city" id="city" onChange="showAllCity(this); return false;">
				<option class="timedCitySelect" value="">-Выберите город-</option>';
					foreach ($arrCity as $arrCity){
		  			$idCity == $arrCity['id_city'] ? $selected='selected="selected"' : $selected = NULL;
	  			$txt .= '<option ' . $selected . ' class="timedCity" value="' . $arrCity['id_city'] . '">' . $arrCity['name'] . '</option>';
  		}
			$txt .= '
				<option class="timedCity" value="typeCity">-Другой-</option>
			</select>';
			echo $txt;
			
  	}
  	elseif (empty($idCity)) { // если не указан город
  		
  		// определяем топ стран, включая выбранную пользователем
  		$arrCountry = Service_Country::getFirstCountry($idCountry);  		
  		
  		echo '
  			<select name="country" id="country" onChange="showCity(this); return false;">
					<option value="NULL" >-Выберите страну-</option>';
					foreach ($arrCountry as $arrCountry){
						$idCountry == $arrCountry['id_country'] ? $selected='selected="selected"' : $selected = NULL;
					echo '<option value="' . $arrCountry['id_country'] . '" ' . $selected . ' >' . $arrCountry['name'] . '</option>';
  		}
  		echo '</select>';
  		
  		// определяем город
  		$idCity = Service_Country::getIdCityFromIP();  		
  		
  		// получаем топ городов страны, включая определенный по ip
  		$arrCity = Service_Country::getFirstCity($idCountry, $idCity);
  		
  		echo '
  		<select name="city" id="city" onChange="showAllCity(this); return false;">
				<option class="timedCitySelect" value="">-Выберите город-</option>';
					foreach ($arrCity as $arrCity){
		  			$idCity == $arrCity['id_city'] ? $selected='selected="selected"' : $selected = NULL;
	  			echo '<option ' . $selected . ' class="timedCity" value="' . $arrCity['id_city'] . '">' . $arrCity['name'] . '</option>';
  		}
			echo '
				<option class="timedCity" value="typeCity">-Другой-</option>
			</select>';
  	}
  	else{
  		
  		// доработать для сохраненного варианта - выводить так же топ стран и городов с выделенными выбрагнными страной и городом
  		
  		$arrCountry = Service_Country::getAllCountry();
  		echo '
  			<select name="country" id="country" onChange="showCity(this); return false;">
					<option value="NULL">-Выберите страну-</option>';
					foreach ($arrCountry as $arrCountry){
						$idCountry == $arrCountry['id_country'] ? $selected='selected="selected"' : $selected = NULL;
					echo '<option value="' . $arrCountry['id_country'] . '" ' . $selected . '>' . $arrCountry['name'] . '</option>';
  		}
  		echo '</select>';


  		$arrCity = Service_Country::getFirstCity($idCountry);
  		echo '
			<select name="city" id="city" onChange="showAllCity(this); return false;"">
				<option class="timedCitySelect" value="">-Выберите город-</option>';
					foreach ($arrCity as $arrCity){
		  			$idCity == $arrCity['id_city'] ? $selected='selected="selected"' : $selected = NULL;
		  			!empty($selected) ? $cityIsset = true : NULL;
	  			echo '<option ' . $selected . ' class="timedCity" value="' . $arrCity['id_city'] . '">' . $arrCity['name'] . '</option>';
  		}
  		if ($cityIsset != true){
  			$cityName = Service_Country::getCityNameById($idCity);
  			echo '<option selected="selectted" class="timedCity" value="' . $idCity . '">' . $cityName . '</option>';
  		}
			echo '
				<option class="timedCity" value="showAllCity">-Показать все города-</option>
			</select>';
			

  	}
  	
  	?>
  	<script type="text/javascript">
		$(document).ready(function () {
/*			$("#city").autocomplete("city.php", {
			delay:10,
			minChars:1,
			matchSubset:1,
			autoFill:true,
			matchContains:1,
			cacheLength:10,
			selectFirst:true,
			maxItemsToShow:10
			}); */	

			$("#city").combobox();


		});
  	</script>
	<style>
	.ui-combobox {
		position: relative;
		display: inline-block;
	}
	.ui-combobox-toggle {
		position: absolute;
		top: 0;
		bottom: 0;
		margin-left: -1px;
		padding: 0;
		/* adjust styles for IE 6/7 */
		*height: 1.7em;
		*top: 0.1em;
	}
	.ui-combobox-input {
		margin: 0;
		padding: 0.3em;
	}
	</style>  	
  	<?
  }  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
}
?>

<!--<div class="labeled fl_l">
	<div id="container8" class="selector_container" style="width: 200px;">
		<table cellspacing="0" cellpadding="0" class="selector_table">
			<tbody>
				<tr>
					<td class="selector">
						<span class="selected_items"></span>
						<input type="text" class="selector_input" style="color: rgb(0, 0, 0); width: 175px;">
						<input type="hidden" class="resultField" value="" id="city" name="city">
						<input type="hidden" class="customField" value="" id="city_custom" name="city_custom">
					</td>
					<td class="selector_dropdown" id="dropdown8" style="width: 16px;">&nbsp;</td>
				</tr>
			</tbody>
		</table>
		
		<div class="results_container">
			<div style="width: 200px; height: 250px; bottom: auto; visibility: visible; display: none;" class="result_list result_list_scrollable">
				<ul style="position: relative; visibility: visible;">
					<li class="disabled first" val="" dis="1">Введите название</li>
					<li class="" val="0" onmousedown="Select.itemMouseDown(8, 1, this)" onmousemove="Select.itemMouseMove(8, 1, this)">- Не выбран -</li>
					<li class="" val="1" onmousedown="Select.itemMouseDown(8, 2, this)" onmousemove="Select.itemMouseMove(8, 2, this)"><b>Москва</b></li>
					<li class="" val="2" onmousedown="Select.itemMouseDown(8, 3, this)" onmousemove="Select.itemMouseMove(8, 3, this)"><b>Санкт-Петербург</b></li>
					<li class="" val="10" onmousedown="Select.itemMouseDown(8, 4, this)" onmousemove="Select.itemMouseMove(8, 4, this)">Волгоград</li>
					<li class="" val="37" onmousedown="Select.itemMouseDown(8, 5, this)" onmousemove="Select.itemMouseMove(8, 5, this)">Владивосток</li>
					<li class="" val="153" onmousedown="Select.itemMouseDown(8, 6, this)" onmousemove="Select.itemMouseMove(8, 6, this)">Хабаровск</li>
					<li class="" val="49" onmousedown="Select.itemMouseDown(8, 7, this)" onmousemove="Select.itemMouseMove(8, 7, this)">Екатеринбург</li>
					<li class="" val="60" onmousedown="Select.itemMouseDown(8, 8, this)" onmousemove="Select.itemMouseMove(8, 8, this)">Казань</li>
					<li class="" val="61" onmousedown="Select.itemMouseDown(8, 9, this)" onmousemove="Select.itemMouseMove(8, 9, this)">Калининград</li>
					<li class="" val="72" onmousedown="Select.itemMouseDown(8, 10, this)" onmousemove="Select.itemMouseMove(8, 10, this)">Краснодар</li>
					<li class="" val="73" onmousedown="Select.itemMouseDown(8, 11, this)" onmousemove="Select.itemMouseMove(8, 11, this)">Красноярск</li>
					<li class="" val="95" onmousedown="Select.itemMouseDown(8, 12, this)" onmousemove="Select.itemMouseMove(8, 12, this)">Нижний Новгород</li>
					<li class="" val="99" onmousedown="Select.itemMouseDown(8, 13, this)" onmousemove="Select.itemMouseMove(8, 13, this)">Новосибирск</li>
					<li class="" val="104" onmousedown="Select.itemMouseDown(8, 14, this)" onmousemove="Select.itemMouseMove(8, 14, this)">Омск</li>
					<li class="" val="110" onmousedown="Select.itemMouseDown(8, 15, this)" onmousemove="Select.itemMouseMove(8, 15, this)">Пермь</li>
					<li class="" val="119" onmousedown="Select.itemMouseDown(8, 16, this)" onmousemove="Select.itemMouseMove(8, 16, this)">Ростов-на-Дону</li>
					<li class="" val="123" onmousedown="Select.itemMouseDown(8, 17, this)" onmousemove="Select.itemMouseMove(8, 17, this)">Самара</li>
					<li class="" val="151" onmousedown="Select.itemMouseDown(8, 18, this)" onmousemove="Select.itemMouseMove(8, 18, this)">Уфа</li>
					<li class="" val="158" onmousedown="Select.itemMouseDown(8, 19, this)" onmousemove="Select.itemMouseMove(8, 19, this)">Челябинск</li>
					<li class="last " val="-1" onmousedown="Select.itemMouseDown(8, 20, this)" onmousemove="Select.itemMouseMove(8, 20, this)">- Другой -</li>
				</ul>
			</div>
			
			<div class="result_list_shadow" style="width: 200px; display: none; margin-top: 251px;">
				<div class="shadow1"></div>
				<div class="shadow2"></div>
			</div>
			
		</div>
	</div>
</div>-->